package com.study.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Solution_228 {
    public static List<String> summaryRanges(int[] nums) {
        List<String> result = new ArrayList<>();
        int index = 0;
        int len = nums.length;
        while (index < len) {
            int end = index;
            while (end + 1 < len && (nums[end] + 1 == nums[end + 1])) {
                end++;
            }
            if (index == end) {
                result.add(String.valueOf(nums[index]));
                index++;
            } else {
                result.add(String.format("%d->%d", nums[index], nums[end]));
                index = end + 1;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        int[] nums = {0,2,3,4,6,8,9};
        List<String> strings = summaryRanges(nums);
        System.out.println("strings = " + strings);
    }
}
